package com.tx.redipubandsub;

/**
 * @description:
 * @author: bluewelkin
 * * @create: 2019-11-06 10:47
 **/
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/*这个文件夹就是另外一个demo，可以直接演示出效果
        https://www.it610.com/article/5084798.htm*/
public class Main {
    public static void main(String[] args) {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxIdle(0);
        config.setMaxTotal(20);
        config.setMaxWaitMillis(1000);
        config.setTestOnBorrow(true);

        //创建连接池
        JedisPool pool = new JedisPool(config, "127.0.0.1", 6379);

        //获取客户端
        Jedis redisClient1 = pool.getResource();
        Jedis redisClient2 = pool.getResource();
        RedisPubSubListener listener = new RedisPubSubListener();


        Subscriber sub = new Subscriber();
        sub.psub(redisClient1, listener); // 订阅一个频道

/*> publish log.info "log is af"  redis-cli输入直接演示效果*/
        Publisher pub = new Publisher();
        pub.publish(redisClient2); //发布一个频道
    }
}